package controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import vo.ScheduleVO;
import dto.ScheduleDTO;

public class SchedulePrivateDeleteSecondController extends HttpServlet {
	
	String schedule_contents_first = null;
	String schedule_all_delete = null;
	
	public SchedulePrivateDeleteSecondController() {
		
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		
		String m_id = (String)req.getParameter("m_id");
 		String schedule_date = (String)req.getParameter("schedule_date");
 		String schedule_title = (String)req.getParameter("schedule_title");
 		int year = Integer.parseInt(schedule_date.substring(0, 4));
		int month = Integer.parseInt(schedule_date.substring(4, 6));
		String schedule_contents_second = (String)req.getParameter("schedule_contents_second");
		String schedule_division = (String)req.getParameter("schedule_division");
		
		if(req.getParameter("schedule_contents_first") != null){
			schedule_contents_first = (String)req.getParameter("schedule_contents_first");
		}else {
			schedule_contents_first = "null";
		}
		
		if(req.getParameter("schedule_all_delete") != null){			
			schedule_all_delete = (String)req.getParameter("schedule_all_delete");
		}else {
			schedule_all_delete = "null";
		}
		
		System.out.println("-------------------[Controller 개인 일정] 두번째 컨텐츠를 삭제 합니다.-------------------");
		System.out.println("m_id: "+m_id);
		System.out.println("date: "+schedule_date);
		System.out.println("title: "+schedule_title);
		System.out.println("year: "+year);
		System.out.println("month: "+month);
		System.out.println("contents_first: "+schedule_contents_first);
		System.out.println("contents_second: "+schedule_contents_second);
		System.out.println("division: "+schedule_division);
		System.out.println("all_delete: "+schedule_all_delete);
		System.out.println("-----------------------------------------------------------------------------");
		
		ScheduleDTO dto = new ScheduleDTO();
		ScheduleVO vo = new ScheduleVO();
		vo.setM_id(m_id);
		vo.setSchedule_date(schedule_date);
		vo.setSchedule_title(schedule_title);
		vo.setSchedule_contents_first(schedule_contents_first);
		vo.setSchedule_contents_second(schedule_contents_second);
		vo.setSchedule_division(schedule_division);
		vo.setSchedule_all_delete(schedule_all_delete);
		
		boolean flag_private_delete_second = dto.privateDeleteSecond(vo);
	
		req.setAttribute("flag_private_delete_second", flag_private_delete_second);
		resp.sendRedirect("/group2/index/main.jsp?inc=../schedule/schedule_private.jsp?month="+month+"&year="+year+"&action=0&left_menu=../schedule/schedule_menu.jsp");
	}
}
